
package com.ru.application.creditscore.domain;

import static org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRICT_READ_WRITE;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.log4j.Logger;
import org.hibernate.annotations.Cache;
import com.google.common.base.Objects;
import com.ru.application.creditscore.domain.IdentifiableHashBuilder;
//import com.ru.application.creditscore.validation.FixedLength;

@Entity
@Table(name = "SCORING_SCHEMA")
@Cache(usage = NONSTRICT_READ_WRITE)
public class ScoringSchema implements Identifiable<Integer>, Serializable {
    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(ScoringSchema.class);

    // Raw attributes
    private Integer id; // pk
    private String name;

    // ---------------------------
    // Constructors
    // ---------------------------

    public ScoringSchema() {
    }

    public ScoringSchema(Integer primaryKey) {
        setId(primaryKey);
    }

    // -------------------------------
    // Getter & Setter
    // -------------------------------

    // -- [id] ------------------------

    @Column(name = "id", precision = 10)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="scoring_schema_id_seq")
    @SequenceGenerator(name="scoring_schema_id_seq", sequenceName="scoring_schema_id_seq",allocationSize=1)
    @Id
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Transient
    public boolean isIdSet() {
        return id != null;
    }

    // -- [name] ------------------------

    //@FixedLength(length = 255)
    @Column(name = "name",length = 255)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * Set the default values.
     */
    public void initDefaultValues() {
    }

    /**
     * equals implementation using a business key.
     */
    @Override
    public boolean equals(Object other) {
        return this == other || (other instanceof ScoringSchema && hashCode() == other.hashCode());
    }

    private IdentifiableHashBuilder identifiableHashBuilder = new IdentifiableHashBuilder();

    @Override
    public int hashCode() {
        return identifiableHashBuilder.hash(log, this);
    }

    /**
     * Construct a readable string representation for this ScoringSchema instance.
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("name", getName()) //
                .toString();
    }

}